package Algo;

public class Summ {
	
	private Summ ()
	{
		
	}

	static int [] summ (int [] a, int[] b)
	{
		if (a.length>b.length)
			return summ_iter (a, b);
		else
			return summ_iter (b, a);
	}		
	
	static int [] summ_iter (int [] max, int [] min)
	{
		int res [] = new int [max.length + 1];
		int i=max.length-1;
		
		for (int j=min.length - 1; j>=0; j--)
		{
			if (max[i]+min[j]+res[i+1]<10)
			{
				res[i+1]=max[i]+min[j]+res[i+1];
				i--;
			}
			else 
			{
				res[i+1]=max[i]+min[j]+res[i+1]-10;
				res[i]=1;
				i--;
			}
		}

		
		for (i=i; i>=0; i--)
			if (max[i]+res[i+1]<10)
			{
				res[i+1]=max[i]+res[i+1];
			}
			else 
			{
				res[i+1]=0;
				res[i]=1;
			}
		return res;		
	}
	
	
	
	
	static void full_mass (int [] a)
	{
		for (int i=0; i<a.length; i++)
			a[i]=(int)(Math.random()*9);
	}
	
	static void print_mass (int []a)
	{
		int i=0;
		while (a[i]==0)
			i++;
		for (i=i; i<a.length; i++)
			System.out.print(a[i] + " ");
		System.out.print("\n");
	}
	
	public static void main(String[] args) 
	{
		int a []  = new int [16];
		int b [] = new int [20];
			
		
		
		
		full_mass(a);
		full_mass(b);
		
		print_mass(a);
		print_mass(b);
		
		print_mass(summ(a,b));

	}

}
